package com.aifast.system.sys.dao;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.aifast.system.sys.entity.SysMessageUser;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;

/**
 * @Author fujian
 * @since 2022/10/19 16:46
 */
@Mapper
public interface SysMessageUserDao extends BaseMapper<SysMessageUser> {

    default LambdaQueryWrapper<SysMessageUser> select(Collection<?> userId, Integer messageId, String read, String beginSendTime, String endSendTime) {
        return new LambdaQueryWrapper<SysMessageUser>()
                .eq(ObjectUtil.isNotNull(messageId), SysMessageUser::getMessageId, messageId)
                .in(ObjectUtil.isNotNull(userId) && userId.size() > 0, SysMessageUser::getUserId, userId)
                .eq(StrUtil.isNotBlank(read), SysMessageUser::getIsRead, read)
                .between(StrUtil.isNotBlank(beginSendTime) && StrUtil.isNotBlank(endSendTime), SysMessageUser::getSendTime, beginSendTime,endSendTime)
                .orderByDesc(SysMessageUser::getId);
    }
}
